package com.six.action.settings;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;
import com.six.biz.IGroupManagementBiz;
import com.six.biz.IGroupPermissionBiz;
import com.six.biz.IPermissionBiz;
import com.six.biz.impl.settings.IGroupManagementBizImpl;
import com.six.biz.impl.settings.IGroupPermissionBizImpl;
import com.six.biz.impl.settings.IPermissionBizImpl;
import com.six.vo.Group;
import com.six.vo.GroupPermission;

@Namespace("/settings")  
@ParentPackage(value = "settings") 
public class GroupManagementAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1148194775682076378L;
	private IGroupManagementBiz groupBiz = new IGroupManagementBizImpl();//组管理业务处理接口
	private IGroupPermissionBiz gpBiz = new IGroupPermissionBizImpl();//组权限管理业务接口
	private IPermissionBiz permissBiz = new IPermissionBizImpl();//权限管理业务接口
	private int gid;
	private String gname;
	private List<Group> glist = new ArrayList<Group>();
	private String optMark;
	private int groupID;
	private String groupName;
	private String groupNote;
	private String groupEditTime;
	private String groupIsDel;
	private String pemission;
	private Group group;
	private GroupPermission gp;
	private int gpid;
	/**
	 * 保存组/修改组
	 */
	@Action(value = "GroupOptAction", 
			results = { 
				@Result(name = "fail", location = "/global/error.jsp") 
				,@Result(name = "success", location = "/manager/GroupManagement.jsp")
			}
	)
	public String optGroupManagement() throws Exception {
		//保存
		groupBiz.saveGroup(group);
		gpBiz.saveGroupPermission(gp);
		//更新
		groupBiz.updateGroup(group);
		gpBiz.deleteGroupPermission(gpid);
		gpBiz.saveGroupPermission(gp);
		
		return null;
		
	}
	/**
	 * 异步响应查询指定组信息
	 */
	@Action(value = "queryGroupInfoAction", 
			results = { 
				@Result(name = "fail", location = "/global/error.jsp") 
				,@Result(name = "success", location = "/manager/GroupManagement.jsp")
			}
	)
	public String queryGroupInfoAction() throws Exception {
		groupBiz.findGroupById(gid);
		return null;
		
	}
	/**
	 * 查询组列表
	 */
	@Action(value = "queryGroupList", 
			results = { 
				@Result(name = "fail", location = "/global/error.jsp") 
				,@Result(name = "success", location = "/manager/GroupManagement.jsp")
			}
	)
	public String queryGroupList() throws Exception {
		groupBiz.findGroupList(gid, gname);
		return null;
		
	}
	/**
	 * 查询未被删除的组列表
	 */
	@Action(value = "queryGroupListForUser")
	public String queryGroupListForUser() throws Exception {
		return null;
		
	}
	/**
	 * 删除组
	 */
	@Action(value = "deleteGroupAction")
	public String deleteGroupAction() throws Exception {
		groupBiz.deleteGroup(gid);
		return null;
		
	}
	/**
	 * 恢复组
	 */
	@Action(value = "revertGroupAction")
	public String revertGroupAction() throws Exception {
		groupBiz.revertGroup(gid);
		return null;
		
	}
	
}
